package lanqiao;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Project : ProgrammingExercises
 * @Package : LanQiao.PrepareForCompetition
 * @File : Q0212.java
 * @Author : WangRuoyu
 * @Date : 2023/3/15 15:31
 */

public class Q0212 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");

        int n = Integer.parseInt(words[0]);
        int[] nums = new int[n];

        words = br.readLine().split(" ");
        for (int i = 0; i < nums.length; ++i) {
            nums[i] = Integer.parseInt(words[i]);
        }

        int res = n;

        for (int i = 0; i < n - 1; ++i) {
            int min = nums[i];
            int max = nums[i];
            for (int j = i + 1; j < n; ++j) {
                min = Math.min(nums[j], min);
                max = Math.max(nums[j], max);

                if (max - min == j - i) {
                    res++;
                }
            }
        }
        System.out.println(res);
    }
}
